<template>
  <div>
    <div class="login-box">
      <h2>巡检机器人登录系统</h2>
      <form>
        <div class="user-box">
          <input type="text" name="" required="" v-model="formData.username" @keyup.enter="handleSubmit()">
          <label>邮箱号</label>
        </div>
        <div class="user-box">
          <input type="password" name="" required="" v-model="formData.password" @keyup.enter="handleSubmit()">
          <label>密码</label>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a @click="handleSubmit()">
          <span></span>
          <span></span>
          <span></span>
          <span></span>
          登录
        </a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a @click="">注册 </a>
      </form>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "LoginView",
  mounted() {
    localStorage.removeItem('token')

  },
  data() {
    return {
      formData: {
        username: '',
        password: ''
      },
    }
  },
  methods: {
    handleEnter() {
      console.log("回车键")
      this.handleSubmit()
    },
    handleSubmit() {
      console.log("来了")
      if (this.formData.username === "" || this.formData.password === "") {
        this.msg = "请输入邮箱密码";
        this.$message.error('请输入邮箱或密码');
      } else {
          if (this.formData.username === 'admin' && this.formData.password === "123456") {
            localStorage.setItem('token', 'admin');
          this.$router.push('/Home');

        } else {
          console.error('登录请求失败');
        }
        // axios.post('http://192.168.1.46:8085/login', this.formData)
        //     .then(res => {
        //       console.log(res.data);
        //       if (res.data.length > 0) {
        //         this.$message.success('登录成功');
        //         localStorage.setItem('token', res.data);
        //         this.$router.push('/home');
        //       } else {
        //         this.$message.error('用户名或密码错误');
        //       }
        //     })
        //     .catch(error => {
        //       console.error('登录请求失败', error);
        //       // this.$message.error('登录失败，请重试');
        //     });
      }
    }
  },
}
;
</script>

<style>
@import "../../assets/css/login/login.css";
</style>
